package tr.edu.metu.is.mega.server.service;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import tr.edu.metu.is.mega.client.service.GwtFileService;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * File service implementation.
 */
public class GwtFileServiceImpl extends RemoteServiceServlet implements GwtFileService {

    private static final long serialVersionUID = -4133415996378348333L;

    /**
     * {@inheritDoc}
     */
    @Override
    public String readFile(String path) {
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(path)));
            String line = "";
            StringBuffer sb = new StringBuffer("");
            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }
            return sb.toString();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }
}
